package P079_HashCodeNotRepeat;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : HashCodeNotRepeat
 * @Description : 集合中的哈希码不要重复
 * @Author : wukj1
 * @Date: 2022/4/7
 **/
public class HashCodeNotRepeat {

    @Test
    public void test(){
        int size = 10000;
        List<String> list = new ArrayList<>(size);

        for (int i = 0; i < size; i++) {
            list.add("value" + i);
        }
        long startTime = System.nanoTime();
        list.contains("value" + (size -1));
        long endTime = System.nanoTime();
        System.out.println("list查找所花时间：" + (endTime - startTime) + "ns");

        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < size; i++) {
            map.put("value" + i,"value" + i);
        }
        long startTime1 = System.nanoTime();
        map.containsKey("value" + (size -1));
        long endTime1 = System.nanoTime();
        System.out.println("map查找所花时间：" + (endTime1 - startTime1) + "ns");
    }

}
